<?php

namespace App\Admin\Controllers;

use App\Models\Article;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ArticleController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '文章管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Article());
        $grid->disableExport();
        $grid->column('id', __('ID'))->sortable();
        $grid->column('type', __('文章类型'))->using(['1' => '隐私政策', '2' => '关于我们']);
        $grid->column('content', __('内容'))->display(function ($content) {

            return "$content";

        });;

        $grid->column('created_at', __('创建时间'));

        $grid->actions(function ($actions) {

            // 去掉查看
            $actions->disableView();
            $actions->disableDelete();
        });
        $grid->disableBatchActions();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Article::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('content', __('内容'));
        $show->field('created_at', __('Created at'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Article());
        $form->select('type', __('文章类型'))->options(['1' => '隐私政策', '2' => '关于我们']);
        $form->UEditor('content','内容')->options(['initialFrameHeight' => 400]);
        $form->footer(function ($footer) {

            // 去掉`查看`checkbox
            $footer->disableViewCheck();

            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
